<template>
  <a-card :bordered="false" class="top-card">
    <a-tabs v-model="activeKey" @change="tabChange">
      <a-tab-pane tab="会员列表" key="Normal" v-has="'customerList:normal'">
        <Normal :filter="filter" :paramTree="paramTree" :fashionerObj="fashionerObj" ref="Normal" :speReasonList="speReasonList" :blackReasonList="blackReasonList" :subType="subTypeList" />
      </a-tab-pane>
      <a-tab-pane tab="特殊名单" key="Special" v-has="'customerList:special'">
        <Special :filter="filter" :paramTree="paramTree" :fashionerObj="fashionerObj" ref="Special" :speReasonList="speReasonList" :blackReasonList="blackReasonList" :subType="subTypeList" />
      </a-tab-pane>
      <a-tab-pane tab="黑名单" key="Black" v-has="'customerList:black'">
        <Black :filter="filter" :paramTree="paramTree" :fashionerObj="fashionerObj" ref="Black" :speReasonList="speReasonList" :blackReasonList="blackReasonList" :subType="subTypeList" />
      </a-tab-pane>
      <a-tab-pane tab="本月新会员" key="Newmember">
        <Newmember :filter="filter" :paramTree="paramTree" :fashionerObj="fashionerObj" ref="Newmember" :speReasonList="speReasonList" :blackReasonList="blackReasonList" :subType="subTypeList" />
      </a-tab-pane>
      <a-tab-pane tab="未服务会员" key="Unserved">
        <Unserved :filter="filter" :paramTree="paramTree" :fashionerObj="fashionerObj" ref="Unserved" :speReasonList="speReasonList" :blackReasonList="blackReasonList" :subType="subTypeList" />
      </a-tab-pane>
    </a-tabs>
  </a-card>
</template>
<script>
import Normal from '@/views/box/customer/customerList/modules/Normal'
import Special from '@/views/box/customer/customerList/modules/Special'
import Black from '@/views/box/customer/customerList/modules/Black'
import Newmember from '@/views/box/customer/customerList/modules/Newmember'
import Unserved from '@/views/box/customer/customerList/modules/Unserved'
import { customerListCondition, getFashioners, getJoinCategoryReasonByCode, getCusListCondition } from '@/api/box/member'
import { fetchSubType } from './modules/tableBase'

export default {
  components: { Normal, Special, Black, Newmember, Unserved },
  data() {
    return {
      fashionerObj: {},
      filter: {},
      speReasonList: [],
      blackReasonList: [],
      activeKey: 'Normal',
      paramTree: [],
      subTypeList: []
    }
  },
  watch: {
    $route(to, from) {
      if (from.path.includes('/box/customer/info')) {
        console.log('******CUS KEEPALIVE**************')
      } else if (to.path.includes('/box/customer/info') && from.path.includes('/box/customer/info')) {
        return false
      } else if (from.path.includes('/box/customer/customerList') && !to.path.includes('/box/customer/info')) {
        console.log('*****CUS destroy*******')
        this.$destroy()
      } else {
        // this.activeKey = 'Normal'
      }
    }
  },
  created() {
    this.getCustomerListCondition()
    this.getJoinCategoryReasonSpe()
    this.getJoinCategoryReasonBlack()
    this.fetchFashioners()
    fetchSubType().then(res => {
      this.subTypeList = res
    })
  },
  activated() {},
  methods: {
    fetchFashioners() {
      getFashioners().then(res => {
        if (res.code == 0) {
          this.fashionerObj.fashioner = res.data
        } else {
          this.$message.warning(res.msg)
        }
      })
    },
    tabChange(activeKey) {
      this.$nextTick(() => {
        switch (activeKey) {
          case 'Normal':
            this.$refs.Normal.$emit('bridge')
            break
          case 'Special':
            this.$refs.Special.$emit('bridge')
            break
          case 'Black':
            this.$refs.Black.$emit('bridge')
            break
          case 'Newmember':
            this.$refs.Newmember.$emit('bridge')
            break
          case 'Unserved':
            this.$refs.Unserved.$emit('bridge')
            break
        }
      })
    },
    // 顾客列表查询条件
    getCustomerListCondition() {
      customerListCondition().then(res => {
        if (res.code === 0) {
          this.filter = res.data
        } else {
          this.$message.error(res.msg)
        }
      })
      getCusListCondition().then(res => {
        if (res.code === 0) {
          this.paramTree = res.data.slice(0, 8)
          for (let item of this.paramTree) {
            Object.assign(item, {
              isMuilt: false,
              isCustom: false,
              checkValue: [],
              checkList: []
              // radioValue: ''
            })
            if (item.name == '会员卡等级') {
              item.isMuilt = true
            }
            if (item.name == '会员积分' || item.name == '集团年消费') {
              item.isCustom = true
              item.cusArr = []
            }
          }
          console.log('****初始化TREE********', this.paramTree)
        } else {
          this.$message.error(res.msg)
        }
      })
    },

    //获取特殊名单原因
    getJoinCategoryReasonSpe() {
      const data = {
        code: 20
      }
      getJoinCategoryReasonByCode(data).then(res => {
        if (res.code === 0) {
          this.speReasonList = res.data
        } else {
          this.$message.error(res.data.msg)
        }
      })
    },

    //黑名单原因
    getJoinCategoryReasonBlack() {
      const data = {
        code: 19
      }
      getJoinCategoryReasonByCode(data).then(res => {
        if (res.code === 0) {
          this.blackReasonList = res.data
        } else {
          this.$message.error(res.data.msg)
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.top-card {
  /deep/ .ant-card-body {
    padding-top: 8px;
    padding-bottom: 8px;
  }
}
</style>

